#include <Windows.h>
#include <iostream>

using namespace std;

void start_exe(string exe_path, string param)
{
    SHELLEXECUTEINFO info = {0};
    info.cbSize = sizeof(info);
    info.fMask = SEE_MASK_NOCLOSEPROCESS;
    info.hwnd = NULL;
    info.lpVerb = NULL;
    info.lpFile = exe_path.c_str();
    info.lpParameters = param.c_str();
    info.lpDirectory = NULL;
    info.nShow = SW_SHOW;

    if (ShellExecuteEx(&info))
    {
        WaitForSingleObject(info.hProcess, INFINITE);
        CloseHandle(info.hProcess);
    }
    else
    {
        cout << "Failed to open program." << endl;
    }
}

int main()
{
    string path = "E:/Project/Repositories/cpp/cpp/httpserver/dist/py/dist/pppppp_MinGW@13.2.0_min.exe";
    // string path = "E:/Project/Repositories/cpp/cpp/httpserver/dist/py/dist/ws/ws.exe";
    // string cmd = "\"{\\\"allowed_origins\\\": [\\\"http://127.0.0.1:6660\\\"], \\\"init\\\": true}\"";
    string cmd = "\"{\\\"allowed_origins\\\": [\\\"http://127.0.0.1:6660\\\"]}\"";
    int port = system((path + " " + cmd).c_str());

    start_exe(path , cmd);
    // cout << port << endl;

    // string killCmd = "taskkill /F /IM ws.exe";
    // int code = system(killCmd.c_str());

    // cout << code << endl;
    return 0;
}